package mmc.server.shell.ops.baseops;

import mmc.server.shell.*;
import mmc.server.shell.ops.Operation;
import mmc.server.shell.ops.PriorityType;

public class Equality extends Operation {

	boolean isObject;
	
    public Equality(String text) throws ShellException {
        super(text, "==", true, true);
        
        if(rValue.hasDoubleOutput()!=lValue.hasDoubleOutput()){
        	throw new OperationNotAcceptedException(true, "cannot compare numerics to objects!");
        }
        
        isObject = !rValue.hasDoubleOutput();
    }

    @Override
    public double execute() {
    	if(isObject)
    		return (lValue.executeComplex() == rValue.executeComplex())?1:0;
    	else{
    		return Util.doubleEquals(lValue.execute(),rValue.execute()) ? 1 : 0;
    	}
    }
    
    public static PriorityType getPriorityType() {
        return PriorityType.COMPARISON;
    }
    
    public static String getDescription(){
    	return formatHelpString("==","compare values or references");
    }
}
